package com.woniu.cms.goods.core.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.woniu.cms.goods.core.entity.GoodsStores;
import com.woniu.cms.goods.core.service.IGoodsStoresService;
import com.woniu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 仓库表 前端控制器
 * </p>
 *
 * @author romantic sheep
 * @since 2022-09-17
 */
@RestController
@Api(tags = "物资仓库模块")
@RequestMapping("/goods-stores")
public class GoodsStoresController {

    @Autowired
    private IGoodsStoresService storesService;
    /*
    * 仓库分页查询方法
    * @currentPage 当前页码
    * @pageSize 页面大小
    * @storeName 用户输入的仓库名称
    * */
    @GetMapping("list")
    @ApiOperation("分页查询/以仓库名称模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "页面大小"),
            @ApiImplicitParam(name = "storeName",value = "仓库名称")
    })
    public Result getList(Integer currentPage, Integer pageSize,String storeName){
        Result result = storesService.getlist(currentPage,pageSize,storeName);
        return result;
    }
    /*
    * 新增仓库的方法
    * @stores 用户输入的仓库对象的
    * */
    @PutMapping("insert")
    @ApiOperation("新增仓库")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stores",value = "添加仓库对象")
    })
    public Result addStore(@RequestBody GoodsStores stores) throws JsonProcessingException {
       Result result= storesService.addStore(stores);
       return result;
    }
    /*
    * 删除仓库的方法，当仓库有被1条或多条材料引用时无法删除
    * @id 仓库id
    * */
    @DeleteMapping("delete/{id}")
    @ApiOperation("删除仓库")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "需删除的仓库id")
    })
    public Result deleteStore(@PathVariable("id") Integer id){
        Result result=storesService.deleteStore(id);
        return result;
    }

}

